<?php
class user_listModel extends baseModel{
    protected $table = 'user';

    //会员列表
    public function user_list($limit=10,$where=null,$order=null) {

        $sql="
            SELECT A.*,B.name as gname
            FROM {$this->model->pre}user A 
            JOIN {$this->model->pre}user_group B ON A.gid = B.gid
            {$where} ORDER BY {$order}A.uid DESC LIMIT {$limit}
            ";
        $data=$this->model->query($sql);
        return $data;
    }

    //总数
    public function count($where=null) {

        $sql="
             SELECT A.*,B.name as gname
            FROM {$this->model->pre}user A 
            JOIN {$this->model->pre}user_group B ON A.gid = B.gid
            {$where}
            ";
        $data=$this->model->query($sql);
        return $data[0]['num'];
    }

    //检测重复用户
    public function user_info($user,$id=null)
    {
        if(!empty($id)){
            $where=' AND id<>'.$id;
        }
        return $this->find('username="'.$user.'"'.$where); 
    }


    //会员信息
    public function info($uid) {
        $sql="
            SELECT B.*,A.*,B.name as gname
            FROM {$this->model->pre}user A 
            JOIN {$this->model->pre}user_group B ON A.gid = B.gid
            WHERE A.uid={$uid} ORDER BY A.uid DESC LIMIT 1
            ";
        $data=$this->model->query($sql);
        return $data[0];
    }

    //获取指定会员列表
    public function content_list($uid) {
        return $this->select('uid in('.$uid.')','','uid desc');
    }

    //添加会员
    public function add($data)
    {
        $ip=get_client_ip();
        $data['reg_time']=time();
        $data['reg_ip']=$ip;
        $data['last_time']=time();
        $data['last_ip']=$ip;
        $data['salt']=getcode(8);
        return $this->insert($data);
    }
    //编辑会员
    public function edit($data)
    {
        $condition['uid']=intval($data['uid']);
        return $this->update($condition,$data); 
        
    }
    //删除会员
    public function del($uid)
    {
        //删除关联
        return $this->delete('uid='.intval($uid)); 
    }

	
}